#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    //child
    int cur = 5;
    while(cur)
    {
      printf("子进程正在运行,pid:%d,ppid:%d\n",getpid(),getppid());
      cur--;
    }
    printf("子进程快退出了,马上变僵尸\n");
    exit(0);
  }
  //父进程
  printf("父进程休眠\n");
  sleep(10);
  printf("回收开始\n");
  pid_t rid = wait(NULL);//阻塞等待
  if(rid>0)
  {
    printf("等待完成,rid:%d\n",rid);
  }
  printf("回收成功\n");
  sleep(3);

  return 0;
}
